package com.tbit.main.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.dao.stat.MachineDayStaDao;
import com.tbit.main.pojo.MachineDaySta;
import com.tbit.main.service.MachineDayStaService;
import com.tbit.main.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author LMY
 * @create 2021-01-06 14:59
 * 用户车辆日统计
 */
@Service("machineDayStaService")
public class MachineDayStaServiceImpl implements MachineDayStaService {
    @Autowired
    private MachineDayStaDao machineDayStaDao;

    @Override
    public void insert(MachineDaySta machineDaySta) {
        machineDayStaDao.insert(machineDaySta);
    }

    @Override
    public void insertRegionId(MachineDaySta machineDaySta) {
        machineDayStaDao.insertRegionId(machineDaySta);
    }

    @Override
    public List<MachineDaySta> getByAccountIdDateDay(List<Integer> accountIds, List<Integer> regionId, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, StringUtil.getListString(accountIds));
        map.put("regionId", StringUtil.getListString(regionId));
        map.put("startDate", startDate);
        map.put("endDate", endDate);
        List<MachineDaySta> machineDayStaList = new LinkedList<>();
        if (accountIds != null && accountIds.size() > 0) {
            machineDayStaList = machineDayStaDao.getByAccountIdDateDay(map);
        }
        if (CollUtil.isNotEmpty(regionId)) {
            List<MachineDaySta> machineDayStas = machineDayStaDao.getByRegionIdDateDay(map);
            machineDayStaList.addAll(machineDayStas);
        }
        return machineDayStaList;
    }

    @Override
    public List<MachineDaySta> getByAccountIdDateWeek(List<Integer> accountIds, List<Integer> regionId, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, StringUtil.getListString(accountIds));
        map.put("regionId", StringUtil.getListString(regionId));
        map.put("startDate", startDate);
        map.put("endDate", endDate);

        List<MachineDaySta> machineDayStaList = new LinkedList<>();
        if (accountIds != null && accountIds.size() > 0) {
            machineDayStaList = machineDayStaDao.getByAccountIdDateWeek(map);
        }
        if (CollUtil.isNotEmpty(regionId)) {
            List<MachineDaySta> machineDayStas = machineDayStaDao.getByRegionIdDateWeek(map);
            machineDayStaList.addAll(machineDayStas);
        }

        return machineDayStaList;
    }

    @Override
    public List<MachineDaySta> getByAccountIdDateMonth(List<Integer> accountIds, List<Integer> regionId, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, StringUtil.getListString(accountIds));
        map.put("regionId", StringUtil.getListString(regionId));
        map.put("startDate", startDate);
        map.put("endDate", endDate);

        List<MachineDaySta> machineDayStaList = new LinkedList<>();
        if (accountIds != null && accountIds.size() > 0) {
            machineDayStaList = machineDayStaDao.getByAccountIdDateMonth(map);
        }
        if (CollUtil.isNotEmpty(regionId)) {
            List<MachineDaySta> machineDayStas = machineDayStaDao.getByRegionIdDateMonth(map);
            machineDayStaList.addAll(machineDayStas);
        }

        return machineDayStaList;
    }

    @Override
    public void update(Integer accountId) {
        machineDayStaDao.update(accountId);
    }

    @Override
    public void updateRegionId(Integer regionId) {
        machineDayStaDao.updateRegionId(regionId);
    }
}
